package com.punch.user.controller;

import com.punch.common.dto.user.guardian.AppSaveStudentDTO;
import com.punch.common.dto.user.guardian.GuardianStudentDTO;
import com.punch.common.enums.user.parentstudent.ParentStudentEnum;
import com.punch.common.model.Result;
import com.punch.common.vo.user.guardian.GuardianStudentVO;
import com.punch.common.vo.user.guardian.SimpleStudentVO;
import com.punch.common.vo.user.student.StudentVO;
import com.punch.user.service.GuardianStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * ParentController-家长 前端控制器
 *
 * @author xiaol
 * @version 1.0.0
 * @since 2020/7/29 22:53
 */
@RestController
@Api(tags = "家长信息表管理（小程序端）")
public class GuardianStudentController {

    @Resource
    private GuardianStudentService guardianChildService;

    /**
     * 保存家长选的学生信息
     *
     * @param guardianStudentDTO 保存信息
     * @return Result 保存信息返回
     */
    @PostMapping("/guardian/student")
    @ApiOperation(value = "保存家长选的学生信息（小程序端）")
    public Result saveGuardianStudent(@Valid @RequestBody GuardianStudentDTO guardianStudentDTO) {
        return Result.succeed(guardianChildService.saveGuardianStudent(guardianStudentDTO));
    }

    /**
     * 家长已添加学生列表
     *
     * @return list
     */
    @GetMapping("/guardian/students")
    @ApiOperation(value = "家长已添加学生列表（小程序端）")
    public Result listGuardianStudent() {
        return Result.succeed(guardianChildService.listGuardianStudent());
    }

//
//    /**
//     * 删除家长选的学生信息
//     *
//     * @param studentId 家长选的学生信息记录id
//     * @return Result 编辑信息返回
//     */
//    @DeleteMapping("/guardian/student/{studentId}")
//    @ApiOperation(value = "删除家长选的学生信息（小程序端）")
//    public Result deleteGuardianStudent(@PathVariable("studentId") Long studentId) {
//        guardianChildService.deleteGuardianStudent(studentId);
//        return Result.succeed(ParentStudentEnum.SUCCESS);
//    }


    /**********************************************app端********************************************************************/
    /**
     * 保存家长选的学生信息
     *
     * @param appSaveStudentDTO 保存信息
     * @return Result 保存信息返回
     */
    @PostMapping("/app-user/student")
    @ApiOperation(value = "App端保存家长选的学生信息")
    public Result<Void> saveStudent(@Valid @RequestBody AppSaveStudentDTO appSaveStudentDTO) {
        guardianChildService.saveStudent(appSaveStudentDTO);
        return Result.succeed("添加成功");
    }

    /**
     * 家长已添加学生列表
     *
     * @author xiaol
     * @since 20207.29 23:10
     */
    @GetMapping(value = "/app-user/students", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "App端家长已添加学生列表", produces = "application/json; charset=utf-8")
    public Result<List<GuardianStudentVO>> listStudent() {
        return Result.succeed(guardianChildService.listGuardianStudent());
    }

    /**
     * App端家长修改学生信息
     *
     * @param guardianStudentDTO 编辑信息
     * @return Result 编辑信息返回
     */
    @PutMapping(value = "/app-user/student", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "App端家长修改学生信息")
    public Result updateGuardianStudent(@RequestBody GuardianStudentDTO guardianStudentDTO) {
        guardianChildService.updateGuardianStudent(guardianStudentDTO);
        return Result.succeed(ParentStudentEnum.SUCCESS);
    }


    /**
     * 删除家长选的学生信息
     *
     * @param studentId 家长选的学生信息记录id
     * @return Result 编辑信息返回
     */
    @DeleteMapping("/app-user/student/{studentId}")
    @ApiOperation(value = "删除家长选的学生信息（小程序端）")
    public Result deleteGuardianStudent(@PathVariable("studentId") Long studentId) {
        guardianChildService.deleteGuardianStudent(studentId);
        return Result.succeed(ParentStudentEnum.SUCCESS);
    }


    /**
     * 根据id查询学生信息
     *
     * @param userId    用户uid
     * @param studentId 学生id
     * @return StudentVO
     */
    @GetMapping(value = "/app-user/{userId}/student/{studentId}")
    @ApiOperation(value = "根据id查询学生信息（App端）")
    public StudentVO getFeignStudentById(@PathVariable("userId") Long userId, @PathVariable("studentId") Long studentId) {
        return guardianChildService.getFeignStudentById(userId, studentId);
    }


    /**
     * APP简单学生列表
     *
     * @author xiaol
     * @since 20207.29 23:10
     */
    @GetMapping(value = "/app-user/simple/students", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "APP简单学生列表", produces = "application/json; charset=utf-8")
    public Result<List<SimpleStudentVO>> listSimpleStudent() {
        return Result.succeed(guardianChildService.listSimpleStudent());
    }
}
